package org.app.config;

import org.app.service.ActivityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * 定时任务配置
 */
@Configuration
@EnableScheduling
public class ScheduleConfig {
    
    private static final Logger log = LoggerFactory.getLogger(ScheduleConfig.class);
    
    @Autowired
    private ActivityService activityService;
    
    /**
     * 每5分钟自动更新活动状态
     * 每天凌晨也会执行一次
     */
    @Scheduled(cron = "0 */5 * * * ?")
    public void updateActivityStatus() {
        log.info("开始执行活动状态自动更新定时任务");
        try {
            activityService.autoUpdateActivityStatus();
            log.info("活动状态自动更新完成");
        } catch (Exception e) {
            log.error("活动状态自动更新失败", e);
        }
    }
} 